$(function () {
    $.fn.zTree.init($("#tree_menu"), setting, zNodes_tree);
    queryMenu();
    fuzzySearch('tree_menu', '#searchMenu', null, true); //初始化模糊搜索方法
});

//**********************左侧树形开始
var setting = {
    view: {
        addHoverDom: addHoverDom,
        removeHoverDom: removeHoverDom,
        selectedMulti: false,
        showIcon: false

    },
    data: {
        simpleData: {
            enable: true
        }
    },
    callback: {
        onClick: zTreeOnClick
    }
};
var zNodes_tree = [{}];
//**********************左侧树形end

//***************************ztree 点击样式 *************
var newCount = 1;
function addHoverDom(treeId, treeNode) {
    var sObj = $("#" + treeNode.tId + "_span");
    if (treeNode.editNameFlag || $("#addBtn_" + treeNode.tId).length > 0) return;
    var addStr = "<span class='button add' id='addBtn_" + treeNode.tId + "' title='add node' onfocus='this.blur();'></span>";
    sObj.after(addStr);
    var btn = $("#addBtn_" + treeNode.tId);
    if (btn) btn.bind("click",
        function () {
            var zTree = $.fn.zTree.getZTreeObj("tree_menu");
            zTree.addNodes(treeNode, {
                id: (100 + newCount),
                pId: treeNode.id,
                name: "new node" + (newCount++)
            });
            return false;
        });
}
;
function removeHoverDom(treeId, treeNode) {
    $("#addBtn_" + treeNode.tId).unbind().remove();
}
;

//***************************ztree 点击样式 *************


/***
 * 根据 所属系统 查找 菜单树
 */
function queryMenu() {
    $.ajax({
        type: "GET",
        contentType: 'application/json',
        dataType: "json",
        url: "menu/queryMenu/" + Common.GetRequest().yydm,
        success: function (jsonData) {
            if (jsonData.code == 200) {
                $.fn.zTree.init($("#tree_menu"), setting, jsonData.menuTreeList);
            } else {
                LayerWn.showFailAlert(jsonData.msg);
            }
        }
    });
}


/***
 *树 单击事件
 */
function zTreeOnClick(event, treeId, treeNode) {
    $(win_obj).find('#sjcd').val(treeNode.name);
    $(win_obj).find('#pcode').val(treeNode.id);
    var index = parent.layer.getFrameIndex(window.name);
    setTimeout(function(){parent.layer.close(index)}, 1000);
}
var win_obj;
function initView(object)
{
    win_obj = object;
}